#include "intersectionplane.h"

IntersectionPlane::IntersectionPlane()
{
    translateX = translateY = translateZ = 0.0;
    translateY = 0.1;
    rotateX = rotateZ = rotateY = 0.0;
}

void IntersectionPlane::AxisRotate()
{
    double matX[4][4], matY[4][4], matZ[4][4];
    CellMath::rotateMatX(rotateX, matX);
    CellMath::rotateMatY(rotateY, matY);
    CellMath::rotateMatZ(rotateZ, matZ);
    double tmp[4][4], result[4][4];
    CellMath::matMutiply(matZ, matY, tmp);
    CellMath::matMutiply(tmp, matX, result);
    double tmpX[4], tmpY[4], tmpZ[4];
    tmpX[0] = tmpX[3] = 1.0;
    tmpX[1] = tmpX[2] = 0.0;
    tmpY[1] = tmpY[3] = 1.0;
    tmpY[0] = tmpY[2] = 0.0;
    tmpZ[2] = tmpZ[3] = 1.0;
    tmpZ[0] = tmpZ[1] = 0.0;
    CellMath::matMutiplyVector(result, tmpX, axisX);
    CellMath::matMutiplyVector(result, tmpY, axisY);
    CellMath::matMutiplyVector(result, tmpZ, axisZ);
    CellMath::rotateMatX(-rotateX, matX);
    CellMath::rotateMatY(-rotateY, matY);
    CellMath::rotateMatZ(-rotateZ, matZ);
    CellMath::matMutiply(matZ, matY, tmp);
    CellMath::matMutiply(tmp, matX, rotateMatrix);
}

void IntersectionPlane::DrawPlane(int id, int selected)
{
    glPushMatrix();
    glLoadName(id);
    glRotated(rotateZ, 0.0, 0.0, 1.0);
    glRotated(rotateY, 0.0, 1.0, 0.0);
    glRotated(rotateX, 1.0, 0.0, 0.0);
    glTranslated(translateX, translateY, translateZ);
    if (selected!=id) {
        glColor3f(40.0/255.0, 40.0/255.0, 40.0/255.0);
    } else {
        glColor3f(140.0/255.0, 140.0/255.0, 140.0/255.0);
    }
    glBegin(GL_QUADS);
    glVertex3d(20.0, 0.0, -20.0);
    glVertex3d(-20.0, 0.0, -20.0);
    glVertex3d(-20.0, 0.0, 20.0);
    glVertex3d(20.0, 0.0, 20.0);
    glEnd();
    glPopMatrix();
}
